package com.qmq.app.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmq.app.dao.EarningsDao;
import com.qmq.app.entity.EarningsEntity;
import com.qmq.app.service.QmqEarningsService;
import com.qmq.common.utils.PageUtils;
import com.qmq.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("QmqEarningsService")
public class QmqEarningsServiceImpl extends ServiceImpl<EarningsDao, EarningsEntity> implements QmqEarningsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<EarningsEntity> page = this.page(
                new Query<EarningsEntity>().getPage(params),
                null
        );
        return new PageUtils(page);
    }

    @Override
    public void add(EarningsEntity dto) {
        this.save(dto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

    @Override
    public void updateByDto(EarningsEntity dto) {
        this.update(Wrappers.<EarningsEntity>lambdaUpdate()
                .set(EarningsEntity::getEarnings, dto.getEarnings())
                .set(EarningsEntity::getName, dto.getName())
                .set(EarningsEntity::getPrice, dto.getPrice())
                .eq(EarningsEntity::getId, dto.getId())
        );
    }
}
